<template>
  <div>
    <!-- Breadcrumb Navigation area -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">Home</el-breadcrumb-item>
      <el-breadcrumb-item>Statistics</el-breadcrumb-item>
      <el-breadcrumb-item>Report</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- Card view area -->
    <el-card>
      <!-- 2. 为ECharts准备一个具备大小（宽高）的Dom -->
      <div id="main" style="width: 950px;height:450px;"></div>
    </el-card>
  </div>
</template>

<script>
/* 1. import echarts */
import echarts from 'echarts'

export default {
  created() {},
  async mounted() {
    // 3. 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'))
    /* 4 Prepare data and data items */
    var tryCount = 5
    var rs
    while (tryCount--) {
      rs = await this.$http.get('reports/type/1')
      if (rs.meta.status !== 200) {
        return this.$msg.error(
          `Get chart data faild, Retrying... remaining times(${tryCount})`
        )
      }
      /* Get data success, break loop */
      break
    }
    for (var key in rs.data) {
      this.options[key] = rs.data[key]
    }
    // 5. 使用刚指定的配置项和数据显示图表。
    myChart.setOption(this.options)
  },
  data() {
    return {
      options: {
        title: {
          text: '用户来源'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#E9EEF3'
            }
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            boundaryGap: false
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ]
      }
    }
  },
  methods: {}
}
</script>

<style lang="less" scoped>
</style>
